/*****************************************************************************
 * vlc_about_dialog.c : About dialog
 *****************************************************************************/

#include "aboutdialog.h"
#include "about_infos.h"

#include <vlc/vlc.h>

#include "gtk_extra/gtk_extra.h"

/* Widget */

static void vlc_about_dialog_class_init (VlcAboutDialogClass *klass);
static void vlc_about_dialog_init       (VlcAboutDialog *dialog);

G_DEFINE_TYPE (VlcAboutDialog, vlc_about_dialog, GTK_TYPE_DIALOG);

/* Internal */

static GtkWidget* create_about_authors_widget (void);
static GtkWidget* create_about_general_info_widget (void);
static GtkWidget* create_about_thanks_widget (void);
static GtkWidget* create_about_distribution_license_widget (void);

/* Callbacks */
static void cb_clicked_close_button (GtkButton *button, gpointer user_data);

static void
vlc_about_dialog_class_init (VlcAboutDialogClass *klass)
{}

static void
vlc_about_dialog_init (VlcAboutDialog *dialog)
{

  GtkWidget *label;
  GtkWidget *hbox;
  GtkWidget *image;
  GtkWidget *button;
  GdkPixbuf *pixbuf;
  
  gtk_window_set_title (GTK_WINDOW (dialog), _("About"));
  gtk_window_set_default_size (GTK_WINDOW (dialog), 532, 480);

  hbox = gtk_hbox_new (FALSE, 10);

  pixbuf = gdk_pixbuf_new_from_file (DATA_PATH"/vlc32x32.png", NULL);
  image = gtk_image_new_from_pixbuf (pixbuf);
  g_object_unref (pixbuf);
  
  gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);

  label = gtk_label_new (_("Information about VLC media player."));
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
  gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);

  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 6);


  dialog->notebook = gtk_notebook_new ();
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), dialog->notebook, TRUE, TRUE, 0);

  gtk_notebook_append_page (GTK_NOTEBOOK (dialog->notebook),\
                            create_about_general_info_widget(),\
                            gtk_label_new (_("General Info")));

  gtk_notebook_append_page (GTK_NOTEBOOK (dialog->notebook),\
                            create_about_authors_widget(),\
                            gtk_label_new (_("Authors")));

  gtk_notebook_append_page (GTK_NOTEBOOK (dialog->notebook),\
                            create_about_thanks_widget(),\
                            gtk_label_new (_("Thanks")));
  
  gtk_notebook_append_page (GTK_NOTEBOOK (dialog->notebook),
                            create_about_distribution_license_widget(),\
                            gtk_label_new (_("Distribution License")));


  button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), button);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cb_clicked_close_button), dialog);

  gtk_widget_show_all (GTK_WIDGET (dialog));

}

/* create our widget */

GtkWidget*
vlc_about_dialog_new (GtkWindow *parent)
{

  GtkWidget *dialog;

  dialog = g_object_new (VLC_TYPE_ABOUT_DIALOG, NULL);
  
  if (parent != NULL)
   {
     gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); 
   }
  
  return dialog;
  
}

/* Private */

static GtkWidget*
create_about_general_info_widget (void)
{

  GtkWidget *label;
  GtkWidget *hbox;
  GtkWidget *image;
  GdkPixbuf *pixbuf;
  gchar *str;

  hbox = gtk_hbox_new (FALSE, 10);

  pixbuf = gdk_pixbuf_new_from_file (DATA_PATH"/vlc128x128.png", NULL);
  image = gtk_image_new_from_pixbuf (pixbuf);
  g_object_unref (pixbuf);
  
  gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);

  str = g_strconcat ("VLC media player " PACKAGE_VERSION "\n\n"
                     "(c) 1996-2007 - the VideoLAN Team\n\n",
                      _("VLC media player is a free media player, made by the "
                        "VideoLAN Team.\nIt is a standalone multimedia player, "
                        "encoder and streamer, that can read from many supports "
                        "(files, CDs, DVDs, networks, capture cards...) and that "
                        " works on many platforms.\n\n"),
                      _("You are using the new Gtk+ Interface.\n"),
                      _("Compiled by "), VLC_CompileBy(), "@", VLC_CompileDomain(), ".\n",
                          "Compiler: ", VLC_Compiler(), ".\n",
                      _( "Based on SVN revision: " ), VLC_Changeset(),
                      ".\n\n",
                      _( "This program comes with NO WARRANTY, to the extent "
                         "permitted by the law; read the distribution tab.\n\n"),
                         "The VideoLAN team <videolan@videolan.org> \n"
                         "http://www.videolan.org/\n",
                      NULL);

  label = gtk_label_new (str);
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
  
  g_free (str);
            
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
  gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);

  return hbox;
  
}

static GtkWidget*
create_about_authors_widget (void)
{

  GtkWidget *scrolled_window;
  GtkWidget *text_view;
  GtkTextBuffer *buffer;
  
  buffer = gtk_text_buffer_new (NULL);
  gtk_text_buffer_set_text (buffer, psz_authors, -1);
  
  text_view = gtk_text_view_new_with_buffer (buffer);
  gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), 4);
  
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_OUT);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

  gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 4);
  gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);

  return scrolled_window;
  
}

static GtkWidget*
create_about_thanks_widget (void)
{

  GtkWidget *vbox;
  GtkWidget *label;
  GtkWidget *scrolled_window;
  GtkWidget *text_view;
  GtkTextBuffer *buffer;

  vbox = gtk_vbox_new (FALSE, 0);

  label = gtk_label_new (_("We would like to thanks the whole "
                           "community, the testers, our users and the following people "
                           "(and the missing ones...) for their collaboration to "
                           "provide the best software."));
  
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);

  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
  gtk_misc_set_padding (GTK_MISC (label), 4, 4);
  gtk_widget_set_size_request (label, 500, -1);

  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  buffer = gtk_text_buffer_new (NULL);
  gtk_text_buffer_set_text (buffer, psz_thanks, -1);
  
  text_view = gtk_text_view_new_with_buffer (buffer);
  gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), 4);
  gtk_text_view_set_right_margin (GTK_TEXT_VIEW (text_view), 4);
  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);

  gtk_widget_set_size_request (text_view, 500, -1);
  
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_OUT);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

  gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 4);
  gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);

  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);

  return vbox;
  
}

static GtkWidget*
create_about_distribution_license_widget (void)
{

  GtkWidget *scrolled_window;
  GtkWidget *text_view;
  GtkTextBuffer *buffer;
  
  buffer = gtk_text_buffer_new (NULL);
  gtk_text_buffer_set_text (buffer, psz_license, -1);
  
  text_view = gtk_text_view_new_with_buffer (buffer);
  gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), 4);
  
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_OUT);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

  gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 4);
  gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);

  return scrolled_window;
  
}

static void
cb_clicked_close_button (GtkButton *button, gpointer user_data)
{

  gtk_widget_destroy (GTK_WIDGET (user_data));

  (void)button;

}


